//
//  EvaluationStarView.m
//  SameWorld(merchant)
//
//  Created by 李小朋 on 2017/3/30.
//  Copyright © 2017年 杨旭. All rights reserved.
//

#import "EvaluationStarView.h"

@interface EvaluationStarView ()
@property (nonatomic ,strong) UIButton *button;
@end

@implementation EvaluationStarView

- (instancetype)initWithFrame:(CGRect)frame andBtn:(UIButton *)btn {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.8];
        self.backgroundColor = [UIColor blackColor];
        self.layer.masksToBounds = YES;
        self.layer.cornerRadius = 2;
        self.button = btn;
        [self creatBtn];
    }
    return self;
}

- (void)creatBtn {
    
    NSArray *titleArr = @[@"一星评价",@"二星评价",@"三星评价",@"四星评价",@"五星评价"];
    for (int i = 0 ; i< 5; i ++) {
        UIButton *btn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        btn.frame = CGRectMake(0, self.frame.size.height/5 * i, self.frame.size.width, self.frame.size.height/5);
        [btn setTitle:titleArr[i] forState:(UIControlStateNormal)];
        [btn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
        btn.titleLabel.font = [UIFont systemFontOfSize:12];
        btn.tag = 2000 + i;
        [btn addTarget:self action:@selector(btnClicked:) forControlEvents:(UIControlEventTouchUpInside)];
        [self addSubview:btn];
        
    }

}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    [UIView animateWithDuration:0.3 animations:^{
        self.button.selected = NO;
        self.alpha = 0;
    }];
}

- (void)btnClicked:(UIButton *)sender{
    
    [self.button setTitle:sender.titleLabel.text forState:(UIControlStateNormal)];
    self.button.selected = NO;
    [UIView animateWithDuration:0.3 animations:^{
        self.alpha = 0;
    }];

}


@end
